package com.lesun.warehouse.Tree;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lesun.warehouse.entity.UnitsBO;
import com.lesun.warehouse.mapper.gen.UnitsMapper;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.List;

@SpringBootTest
public class TreeDemo {

    @Resource
    private UnitsMapper unitsMapper;

    @Test
    public void test() {

        List<UnitsBO> list = unitsMapper.selectList(
                new LambdaQueryWrapper<UnitsBO>());
        TreeNodeUtil<UnitsBO> treeNodeUtil = new TreeNodeUtil<>(list);
        treeNodeUtil.setRootNodeFunc((bo) ->
                bo.getParentCode() == null || bo.getParentCode().equals(""));
        treeNodeUtil.setNodeFunc((bo, parent) -> bo.getCode().equals(parent.getParentCode()));
        List<UnitsBO> tree = treeNodeUtil.buildTree((bo, boChildren) -> bo.setChildren(boChildren));
        System.out.println(tree);
    }
}